using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using NUnit.Framework;

namespace dlw.S3Examples
{
    public class TestMisc
    {
        private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public SortedList GetTests()
        {
            SortedList allTests = new SortedList();
            Assembly theAss = Assembly.GetEntryAssembly();
            Type[] types = theAss.GetTypes();
            foreach (Type typ in types)
            {
                Object[] att = typ.GetCustomAttributes(typeof(TestClassAttribute), false);
                if (att.Length < 1) continue; // this is not a test class
                // this is a testClass
                if (allTests.ContainsKey(typ.Name))
                {
                    log.Warn("Test Class is defined more than once: " + typ.Name);
                    continue;
                }
                SortedList allMethods = new SortedList();
                allTests.Add(typ.Name, allMethods);
                foreach (MethodInfo mi in typ.GetMethods())
                {
                    Object[] testMethods = mi.GetCustomAttributes(typeof(TestMethodAttribute), false);
                    if (testMethods.Length < 1)
                    {
                        continue;   // ths is not a test method
                    }
                    string key = mi.Name;
                    foreach (ParameterInfo pi in mi.GetParameters())
                    {
                        key = " " + pi.Name;
                    }
                }
            }
            return allTests;
        }
    }
    public class TestList : SortedList<string, TestType>
    {
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(GetType().Name);
            foreach (TestType ti in Values)
            {
                sb.Append(ti.Name + ": " + ti.GetType().Name);
            }
            return sb.ToString();
        }
    }
    public class TestType: SortedList<string, TestMethod>
    {
        public string Name;
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(GetType().Name);
            foreach (TestMethod ti in Values)
            {
                sb.Append(ti.Name + ": " + ti.GetType().Name);
            }
            return sb.ToString();
        }
    }
    public class TestMethod : SortedList<string, TestParam>
    {
        public string Name;
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(GetType().Name);
            foreach (TestParam pi in Values)
            {
                sb.Append(pi.Name + ": " + pi.GetType().Name);
            }
            return sb.ToString();
        }
    }
    public class TestMethodList : SortedList<string, TestMethod> { }

    public class TestParam : SortedList<string, ParameterInfo>
    {
        public string Name;
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(GetType().Name);
            return sb.ToString();
        }
    }
}

